package com.zys.el.upload.controller;

import com.zys.el.upload.utils.AliyunSTSToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Map;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("oss")
public class AliyunOssController {
    @Autowired
    private AliyunSTSToken aliyunSTSToken;

    @GetMapping("sts")
    public Map<String, String> getStsToken(@RequestParam("type") String type) throws InterruptedException {
        log.debug(type);
        if (StringUtils.isBlank(type)) return Collections.singletonMap("ERROR", "参数有误");
        switch (type) {
            case "channel":
                Map<String, String> sts = aliyunSTSToken.getSTS();
                sts.put("bucket", "elearninge");
                log.debug(String.valueOf(sts));
                return sts;
            default:
                return Collections.singletonMap("ERROR", "参数有误");
        }
    }
}
